





<!DOCTYPE html>
<html class="writer-html5" lang="zh-CN" >
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Debugger &mdash; tvm 0.8.dev1982 文档</title>
  

  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/gallery.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tlcpack_theme.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../_static/tvm-logo-square.png"/>
  

  
  
  
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    
    <script type="text/javascript" src="../_static/js/tlcpack_theme.js"></script>
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="Putting the VM in TVM: The Relay Virtual Machine" href="virtual_machine.html" />
    <link rel="prev" title="Vulkan Runtime" href="runtimes/vulkan.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    
<header class="header">
    <div class="innercontainer">
      <div class="headerInner d-flex justify-content-between align-items-center">
          <div class="headerLogo">
               <a href="https://tvm.apache.org/"><img src=https://tvm.apache.org/assets/images/logo.svg alt="logo"></a>
          </div>

          <div id="headMenu" class="headerNav">
            <button type="button" id="closeHeadMenu" class="navCloseBtn"><img src="../_static/img/close-icon.svg" alt="Close"></button>
             <ul class="nav">
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/community>Community</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/download>Download</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/vta>VTA</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/blog>Blog</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/docs>Docs</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvmconf.org>Conference</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://github.com/apache/tvm/>Github</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvmchinese.github.io/declaration_zh_CN.html>About-Translators</a>
                </li>
             </ul>
               <div class="responsivetlcdropdown">
                 <button type="button" class="btn-link">
                   ASF
                 </button>
                 <ul>
                     <li>
                       <a href=https://apache.org/>Apache Homepage</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/licenses/>License</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/security/>Security</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/thanks.html>Thanks</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/events/current-event>Events</a>
                     </li>
                     <li>
                       <a href=https://www.zhihu.com/column/c_1429578595417563136>Zhihu</a>
                     </li>
                 </ul>
               </div>
          </div>
            <div class="responsiveMenuIcon">
              <button type="button" id="menuBtn" class="btn-menu"><img src="../_static/img/menu-icon.svg" alt="Menu Icon"></button>
            </div>

            <div class="tlcDropdown">
              <div class="dropdown">
                <button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  ASF
                </button>
                <div class="dropdown-menu dropdown-menu-right">
                  <ul>
                     <li>
                       <a href=https://apache.org/>Apache Homepage</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/licenses/>License</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/security/>Security</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/thanks.html>Thanks</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/events/current-event>Events</a>
                     </li>
                     <li>
                       <a href=https://www.zhihu.com/column/c_1429578595417563136>Zhihu</a>
                     </li>
                  </ul>
                </div>
              </div>
          </div>
       </div>
    </div>
 </header>
 
    <nav data-toggle="wy-nav-shift" class="wy-nav-side fixed">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html">
          

          
            
            <img src="../_static/tvm-logo-small.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
                <div class="version">
                  0.8.dev1982
                </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption" role="heading"><span class="caption-text">如何开始</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../install/index.html">安装 TVM</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contribute/index.html">贡献者指南</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">用户引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">User Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../how_to/index.html">How To Guides</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">开发者引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../dev/tutorial/index.html">Developer Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../dev/how_to/how_to.html">开发者指南</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">架构指南</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Design and Architecture</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="index.html#example-compilation-flow">编译流程示例</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#logical-architecture-components">逻辑架构组件</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#tvm-support">tvm/support</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html#tvm-runtime">tvm/runtime</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="runtime.html">TVM runtime系统</a></li>
<li class="toctree-l3"><a class="reference internal" href="runtime.html#runtime-specific-information">Runtime-Specific Information</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">Debugger</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#debug-exchange-format">Debug Exchange Format</a></li>
<li class="toctree-l4"><a class="reference internal" href="#how-to-use-debugger">How to use Debugger?</a></li>
<li class="toctree-l4"><a class="reference internal" href="#sample-output">样本输出</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="virtual_machine.html">Putting the VM in TVM: The Relay Virtual Machine</a></li>
<li class="toctree-l3"><a class="reference internal" href="introduction_to_module_serialization.html">Introduction to Module Serialization</a></li>
<li class="toctree-l3"><a class="reference internal" href="device_target_interactions.html">Device/Target Interactions</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="index.html#tvm-node">tvm/node</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#tvm-ir">tvm/ir</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#tvm-target">tvm/target</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#tvm-tir">tvm/tir</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#tvm-arith">tvm/arith</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#tvm-te">tvm/te</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#tvm-topi">tvm/topi</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#tvm-relay">tvm/relay</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#tvm-autotvm">tvm/autotvm</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#frontends">Frontends</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#security">安全</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#microtvm">microTVM</a></li>
</ul>
</li>
</ul>
<p class="caption" role="heading"><span class="caption-text">主题引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../topic/microtvm/index.html">microTVM：裸机使用TVM</a></li>
<li class="toctree-l1"><a class="reference internal" href="../topic/vta/index.html">VTA: Versatile Tensor Accelerator</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">参考指南</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../reference/langref/index.html">语言参考</a></li>
<li class="toctree-l1"><a class="reference internal" href="../reference/api/python/index.html">Python API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../reference/api/links.html">Other APIs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../reference/publications.html">Publications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../genindex.html">索引</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
      
      <nav class="wy-nav-top" aria-label="top navigation" data-toggle="wy-nav-top">
        
            <div class="togglemenu">

            </div>
            <div class="nav-content">
              <!-- tvm -->
              Table of content
            </div>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        

          




















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> <span class="br-arrow">></span></li>
        
          <li><a href="index.html">Design and Architecture</a> <span class="br-arrow">></span></li>
        
      <li>Debugger</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/arch/debugger.rst.txt" rel="nofollow"> <img src="../_static//img/source.svg" alt="viewsource"/></a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="debugger">
<h1>Debugger<a class="headerlink" href="#debugger" title="永久链接至标题">¶</a></h1>
<p>TVM Debugger is an interface for debugging TVM’s computation graph execution. It helps to provide access to graph structures and tensor values at the TVM runtime.</p>
<div class="section" id="debug-exchange-format">
<h2>Debug Exchange Format<a class="headerlink" href="#debug-exchange-format" title="永久链接至标题">¶</a></h2>
<div class="section" id="computational-graph">
<h3>1. Computational Graph<a class="headerlink" href="#computational-graph" title="永久链接至标题">¶</a></h3>
<p>The optimized graph build by relay in json
serialized format is dumped as it is. This contains the whole
information about the graph. The UX can either use this graph directly
or transform this graph to the format UX can understand.</p>
<p>The Graph JSON format is explained below</p>
<p>1. <code class="docutils literal notranslate"><span class="pre">nodes</span></code>
Nodes are either placeholders or computational nodes in json. The nodes are stored
as a list. A node contains the below information</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">op</span></code> - operation type, <code class="docutils literal notranslate"><span class="pre">null</span></code> means it is a placeholder/variable/input node and``tvm_op`` means this node can be executed</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">name</span></code> - Name of the node</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">inputs</span></code> - Position of the inputs for this operation, Inputs is a list of tuples with (nodeid, index, version). (Optional)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">attrs</span></code> - Attributes of the node which contains the following information</p></li>
</ul>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">flatten_data</span></code> - Whether this data need to be flattened before execution</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">func_name</span></code> - Fused function name, corresponds to the symbol in the lib generated by relay compilation process.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_inputs</span></code> - Number of inputs for this node</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">num_outputs</span></code> - Number of outputs this node produces</p></li>
</ul>
</div></blockquote>
<p>2. <code class="docutils literal notranslate"><span class="pre">arg_nodes</span></code>
arg_nodes is a list of indices of nodes which is placeholder/variable/input or constant/param to the graph.</p>
<p>3. <code class="docutils literal notranslate"><span class="pre">heads</span></code>
heads is a list of entries as the output of the graph.</p>
<p>4. <code class="docutils literal notranslate"><span class="pre">node_row_ptr</span></code>
node_row_ptr stores the history of forward path, so you can skip constructing the entire graph in inference tasks.</p>
<p>5. <code class="docutils literal notranslate"><span class="pre">attrs</span></code>
attrs can contain version numbers or similar helpful information.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">storage_id</span></code> - Memory slot id for each node in the storage layout.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">dtype</span></code> - Datatype of each node (enum value).</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">dltype</span></code> - Datatype of each node in order.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">shape</span></code> - Shape of each node k order.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">device_index</span></code> - Device assignment for each entry in the graph.</p></li>
</ul>
<p>Example of dumped graph:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
  <span class="s2">&quot;nodes&quot;</span><span class="p">:</span> <span class="p">[</span>                                    <span class="c1"># List of nodes</span>
    <span class="p">{</span>
      <span class="s2">&quot;op&quot;</span><span class="p">:</span> <span class="s2">&quot;null&quot;</span><span class="p">,</span>                             <span class="c1"># operation type = null, this is a placeholder/variable/input or constant/param node</span>
      <span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;x&quot;</span><span class="p">,</span>                              <span class="c1"># Name of the argument node</span>
      <span class="s2">&quot;inputs&quot;</span><span class="p">:</span> <span class="p">[]</span>                              <span class="c1"># inputs for this node, its none since this is an argument node</span>
    <span class="p">},</span>
    <span class="p">{</span>
      <span class="s2">&quot;op&quot;</span><span class="p">:</span> <span class="s2">&quot;tvm_op&quot;</span><span class="p">,</span>                           <span class="c1"># operation type = tvm_op, this node can be executed</span>
      <span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;relu0&quot;</span><span class="p">,</span>                          <span class="c1"># Name of the node</span>
      <span class="s2">&quot;attrs&quot;</span><span class="p">:</span> <span class="p">{</span>                                <span class="c1"># Attributes of the node</span>
        <span class="s2">&quot;flatten_data&quot;</span><span class="p">:</span> <span class="s2">&quot;0&quot;</span><span class="p">,</span>                    <span class="c1"># Whether this data need to be flattened</span>
        <span class="s2">&quot;func_name&quot;</span><span class="p">:</span> <span class="s2">&quot;fuse_l2_normalize_relu&quot;</span><span class="p">,</span>  <span class="c1"># Fused function name, corresponds to the symbol in the lib generated by compilation process</span>
        <span class="s2">&quot;num_inputs&quot;</span><span class="p">:</span> <span class="s2">&quot;1&quot;</span><span class="p">,</span>                      <span class="c1"># Number of inputs for this node</span>
        <span class="s2">&quot;num_outputs&quot;</span><span class="p">:</span> <span class="s2">&quot;1&quot;</span>                      <span class="c1"># Number of outputs this node produces</span>
      <span class="p">},</span>
      <span class="s2">&quot;inputs&quot;</span><span class="p">:</span> <span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]]</span>                     <span class="c1"># Position of the inputs for this operation</span>
    <span class="p">}</span>
  <span class="p">],</span>
  <span class="s2">&quot;arg_nodes&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">],</span>                             <span class="c1"># Which all nodes in this are argument nodes</span>
  <span class="s2">&quot;node_row_ptr&quot;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span>                    <span class="c1"># Row indices for faster depth first search</span>
  <span class="s2">&quot;heads&quot;</span><span class="p">:</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]],</span>                         <span class="c1"># Position of the output nodes for this operation</span>
  <span class="s2">&quot;attrs&quot;</span><span class="p">:</span> <span class="p">{</span>                                    <span class="c1"># Attributes for the graph</span>
    <span class="s2">&quot;storage_id&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;list_int&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]],</span>         <span class="c1"># memory slot id for each node in the storage layout</span>
    <span class="s2">&quot;dtype&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;list_int&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]],</span>              <span class="c1"># Datatype of each node (enum value)</span>
    <span class="s2">&quot;dltype&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;list_str&quot;</span><span class="p">,</span> <span class="p">[</span>                    <span class="c1"># Datatype of each node in order</span>
        <span class="s2">&quot;float32&quot;</span><span class="p">,</span>
        <span class="s2">&quot;float32&quot;</span><span class="p">]],</span>
    <span class="s2">&quot;shape&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;list_shape&quot;</span><span class="p">,</span> <span class="p">[</span>                   <span class="c1"># Shape of each node k order</span>
        <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">20</span><span class="p">],</span>
        <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">20</span><span class="p">]]],</span>
    <span class="s2">&quot;device_index&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;list_int&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]],</span>       <span class="c1"># Device assignment for each node in order</span>
  <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="tensor-dumping">
<h3>2. Tensor dumping<a class="headerlink" href="#tensor-dumping" title="永久链接至标题">¶</a></h3>
<p>The tensor received after execution is in <code class="docutils literal notranslate"><span class="pre">tvm.ndarray</span></code> type. All the tensors will
be saved as binary bytes in serialized format.  The result binary bytes can be loaded by the
API “load_params”.</p>
<dl>
<dt>Example of loading the parameters</dt><dd><dl>
<dt>::</dt><dd><dl class="simple">
<dt>with open(path_params, “rb”) as fi:</dt><dd><p>loaded_params = bytearray(fi.read())</p>
</dd>
</dl>
<p>module.load_params(loaded_params)</p>
</dd>
</dl>
</dd>
</dl>
</div>
</div>
<div class="section" id="how-to-use-debugger">
<h2>How to use Debugger?<a class="headerlink" href="#how-to-use-debugger" title="永久链接至标题">¶</a></h2>
<ol class="arabic">
<li><p>In <code class="docutils literal notranslate"><span class="pre">config.cmake</span></code> set the <code class="docutils literal notranslate"><span class="pre">USE_PROFILER</span></code> flag to <code class="docutils literal notranslate"><span class="pre">ON</span></code></p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Whether enable additional graph debug functions</span>
<span class="nb">set</span><span class="p">(</span><span class="n">USE_PROFILER</span> <span class="n">ON</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p>Do ‘make’ tvm, so that it will make the <code class="docutils literal notranslate"><span class="pre">libtvm_runtime.so</span></code></p></li>
<li><p>In frontend script file instead of
<code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">tvm.contrib</span> <span class="pre">import</span> <span class="pre">graph_executor</span></code> import the
<code class="docutils literal notranslate"><span class="pre">debug_executor</span></code>
<code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">tvm.contrib.debugger</span> <span class="pre">import</span> <span class="pre">debug_executor</span> <span class="pre">as</span> <span class="pre">graph_executor</span></code></p></li>
</ol>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">tvm.contrib.debugger</span> <span class="k">import</span> <span class="n">debug_executor</span> <span class="k">as</span> <span class="n">graph_executor</span>
<span class="n">m</span> <span class="o">=</span> <span class="n">graph_executor</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">graph</span><span class="p">,</span> <span class="n">lib</span><span class="p">,</span> <span class="n">dev</span><span class="p">,</span> <span class="n">dump_root</span><span class="o">=</span><span class="s2">&quot;/tmp/tvmdbg&quot;</span><span class="p">)</span>
<span class="c1"># set inputs</span>
<span class="n">m</span><span class="o">.</span><span class="n">set_input</span><span class="p">(</span><span class="s1">&#39;data&#39;</span><span class="p">,</span> <span class="n">tvm</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">dtype</span><span class="p">)))</span>
<span class="n">m</span><span class="o">.</span><span class="n">set_input</span><span class="p">(</span><span class="o">**</span><span class="n">params</span><span class="p">)</span>
<span class="c1"># execute</span>
<span class="n">m</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
<span class="n">tvm_out</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">get_output</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">tvm</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="n">out_shape</span><span class="p">,</span> <span class="n">dtype</span><span class="p">))</span><span class="o">.</span><span class="n">numpy</span><span class="p">()</span>
</pre></div>
</div>
<ol class="arabic simple" start="4">
<li><dl class="simple">
<dt>If network previously was exported to external libray using <code class="docutils literal notranslate"><span class="pre">lib.export_library(&quot;network.so&quot;)</span></code></dt><dd><p>like shared object file/dynamic linked library, the initialization
of debug runtime will be slightly different</p>
</dd>
</dl>
</li>
</ol>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">lib</span> <span class="o">=</span> <span class="n">tvm</span><span class="o">.</span><span class="n">runtime</span><span class="o">.</span><span class="n">load_module</span><span class="p">(</span><span class="s2">&quot;network.so&quot;</span><span class="p">)</span>
<span class="n">m</span> <span class="o">=</span> <span class="n">graph_executor</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">lib</span><span class="p">[</span><span class="s2">&quot;get_graph_json&quot;</span><span class="p">](),</span> <span class="n">lib</span><span class="p">,</span> <span class="n">dev</span><span class="p">,</span> <span class="n">dump_root</span><span class="o">=</span><span class="s2">&quot;/tmp/tvmdbg&quot;</span><span class="p">)</span>
<span class="c1"># set inputs</span>
<span class="n">m</span><span class="o">.</span><span class="n">set_input</span><span class="p">(</span><span class="s1">&#39;data&#39;</span><span class="p">,</span> <span class="n">tvm</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">dtype</span><span class="p">)))</span>
<span class="n">m</span><span class="o">.</span><span class="n">set_input</span><span class="p">(</span><span class="o">**</span><span class="n">params</span><span class="p">)</span>
<span class="c1"># execute</span>
<span class="n">m</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
<span class="n">tvm_out</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">get_output</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">tvm</span><span class="o">.</span><span class="n">nd</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="n">out_shape</span><span class="p">,</span> <span class="n">dtype</span><span class="p">))</span><span class="o">.</span><span class="n">numpy</span><span class="p">()</span>
</pre></div>
</div>
<p>The outputs are dumped to a temporary folder in <code class="docutils literal notranslate"><span class="pre">/tmp</span></code> folder or the
folder specified while creating the runtime.</p>
</div>
<div class="section" id="sample-output">
<h2>样本输出<a class="headerlink" href="#sample-output" title="永久链接至标题">¶</a></h2>
<p>The below is the an example output of the debugger.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Node</span> <span class="n">Name</span>               <span class="n">Ops</span>                                                                  <span class="n">Time</span><span class="p">(</span><span class="n">us</span><span class="p">)</span>   <span class="n">Time</span><span class="p">(</span><span class="o">%</span><span class="p">)</span>  <span class="n">Start</span> <span class="n">Time</span>       <span class="n">End</span> <span class="n">Time</span>         <span class="n">Shape</span>                <span class="n">Inputs</span>  <span class="n">Outputs</span>
<span class="o">---------</span>               <span class="o">---</span>                                                                  <span class="o">--------</span>   <span class="o">-------</span>  <span class="o">----------</span>       <span class="o">--------</span>         <span class="o">-----</span>                <span class="o">------</span>  <span class="o">-------</span>
<span class="mi">1</span><span class="n">_NCHW1c</span>                <span class="n">fuse___layout_transform___4</span>                                          <span class="mf">56.52</span>      <span class="mf">0.02</span>     <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.177475</span>  <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.177534</span>  <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">224</span><span class="p">,</span> <span class="mi">224</span><span class="p">)</span>     <span class="mi">1</span>       <span class="mi">1</span>
<span class="n">_contrib_conv2d_nchwc0</span>  <span class="n">fuse__contrib_conv2d_NCHWc</span>                                           <span class="mf">12436.11</span>   <span class="mf">3.4</span>      <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.177549</span>  <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.189993</span>  <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">224</span><span class="p">,</span> <span class="mi">224</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>  <span class="mi">2</span>       <span class="mi">1</span>
<span class="n">relu0_NCHW8c</span>            <span class="n">fuse___layout_transform___broadcast_add_relu___layout_transform__</span>    <span class="mf">4375.43</span>    <span class="mf">1.2</span>      <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.190027</span>  <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.194410</span>  <span class="p">(</span><span class="mi">8</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">8</span><span class="p">)</span>   <span class="mi">2</span>       <span class="mi">1</span>
<span class="n">_contrib_conv2d_nchwc1</span>  <span class="n">fuse__contrib_conv2d_NCHWc_1</span>                                         <span class="mf">213108.6</span>   <span class="mf">58.28</span>    <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.194440</span>  <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.407558</span>  <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">224</span><span class="p">,</span> <span class="mi">224</span><span class="p">,</span> <span class="mi">8</span><span class="p">)</span>  <span class="mi">2</span>       <span class="mi">1</span>
<span class="n">relu1_NCHW8c</span>            <span class="n">fuse___layout_transform___broadcast_add_relu___layout_transform__</span>    <span class="mf">2265.57</span>    <span class="mf">0.62</span>     <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.407600</span>  <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.409874</span>  <span class="p">(</span><span class="mi">64</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>           <span class="mi">2</span>       <span class="mi">1</span>
<span class="n">_contrib_conv2d_nchwc2</span>  <span class="n">fuse__contrib_conv2d_NCHWc_2</span>                                         <span class="mf">104623.15</span>  <span class="mf">28.61</span>    <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.409905</span>  <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.514535</span>  <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">224</span><span class="p">,</span> <span class="mi">224</span><span class="p">,</span> <span class="mi">8</span><span class="p">)</span>  <span class="mi">2</span>       <span class="mi">1</span>
<span class="n">relu2_NCHW2c</span>            <span class="n">fuse___layout_transform___broadcast_add_relu___layout_transform___1</span>  <span class="mf">2004.77</span>    <span class="mf">0.55</span>     <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.514567</span>  <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.516582</span>  <span class="p">(</span><span class="mi">8</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">8</span><span class="p">)</span>   <span class="mi">2</span>       <span class="mi">1</span>
<span class="n">_contrib_conv2d_nchwc3</span>  <span class="n">fuse__contrib_conv2d_NCHWc_3</span>                                         <span class="mf">25218.4</span>    <span class="mf">6.9</span>      <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.516628</span>  <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.541856</span>  <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">224</span><span class="p">,</span> <span class="mi">224</span><span class="p">,</span> <span class="mi">8</span><span class="p">)</span>  <span class="mi">2</span>       <span class="mi">1</span>
<span class="n">reshape1</span>                <span class="n">fuse___layout_transform___broadcast_add_reshape_transpose_reshape</span>    <span class="mf">1554.25</span>    <span class="mf">0.43</span>     <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.541893</span>  <span class="mi">15</span><span class="p">:</span><span class="mi">24</span><span class="p">:</span><span class="mf">44.543452</span>  <span class="p">(</span><span class="mi">64</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>           <span class="mi">2</span>       <span class="mi">1</span>
</pre></div>
</div>
</div>
</div>


           </div>
           
          </div>
          

<footer>

    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="virtual_machine.html" class="btn btn-neutral float-right" title="Putting the VM in TVM: The Relay Virtual Machine" accesskey="n" rel="next">下一个 <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="runtimes/vulkan.html" class="btn btn-neutral float-left" title="Vulkan Runtime" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> 上一个</a>
      
    </div>

<div id="button" class="backtop"><img src="../_static//img/right.svg" alt="backtop"/> </div>
<section class="footerSec">
    <div class="footerHeader">
      <ul class="d-flex align-md-items-center justify-content-between flex-column flex-md-row">
        <li class="copywrite d-flex align-items-center">
          <h5 id="copy-right-info">© 2020 Apache Software Foundation | All right reserved</h5>
        </li>
      </ul>

    </div>

    <ul>
      <li class="footernote">Copyright © 2020 The Apache Software Foundation. Apache TVM, Apache, the Apache feather, and the Apache TVM project logo are either trademarks or registered trademarks of the Apache Software Foundation.</li>
    </ul>

</section>
</footer>
        </div>
      </div>

    </section>

  </div>
  

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

  </body>
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
    <!-- Theme Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-75982049-2', 'auto');
    ga('send', 'pageview');
    </script>

    
   

</body>
</html>